{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "091590f8",
   "metadata": {},
   "source": [
    "# 测试文件\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "62c50aa6",
   "metadata": {},
   "outputs": [],
   "source": [
    "from continuallearning.events.interfaces import *"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "c29252e1",
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/home/jiashuo/workspace/codespace/lightning_continual_framework/.venv/lib/python3.11/site-packages/tqdm/auto.py:21: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n"
     ]
    },
    {
     "ename": "ImportError",
     "evalue": "cannot import name 'EventHandlerInterface' from partially initialized module 'continuallearning.events.interfaces' (most likely due to a circular import) (/data1/jiashuo/codespace/lightning_continual_framework/continuallearning/events/interfaces/__init__.py)",
     "output_type": "error",
     "traceback": [
      "\u001b[31m---------------------------------------------------------------------------\u001b[39m",
      "\u001b[31mImportError\u001b[39m                               Traceback (most recent call last)",
      "\u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[1]\u001b[39m\u001b[32m, line 2\u001b[39m\n\u001b[32m      1\u001b[39m \u001b[38;5;66;03m# 导入必要组件\u001b[39;00m\n\u001b[32m----> \u001b[39m\u001b[32m2\u001b[39m \u001b[38;5;28;01mfrom\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[34;01mcontinuallearning\u001b[39;00m\u001b[34;01m.\u001b[39;00m\u001b[34;01mevents\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[38;5;28;01mimport\u001b[39;00m (\n\u001b[32m      3\u001b[39m     EventType, EventFactory, FunctionalEventHandler, global_dispatcher\n\u001b[32m      4\u001b[39m )\n\u001b[32m      6\u001b[39m \u001b[38;5;66;03m# 🎪 步骤1: 创建事件处理器（就是一个函数！）\u001b[39;00m\n\u001b[32m      7\u001b[39m \u001b[38;5;28;01mdef\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[34mhello_handler\u001b[39m(event):\n",
      "\u001b[36mFile \u001b[39m\u001b[32m/data1/jiashuo/codespace/lightning_continual_framework/continuallearning/events/__init__.py:18\u001b[39m\n\u001b[32m      1\u001b[39m \u001b[38;5;66;03m# Event-Driven Continual Learning Framework\u001b[39;00m\n\u001b[32m      2\u001b[39m \u001b[38;5;66;03m#\u001b[39;00m\n\u001b[32m      3\u001b[39m \u001b[38;5;66;03m# This package provides a comprehensive event-driven architecture for\u001b[39;00m\n\u001b[32m   (...)\u001b[39m\u001b[32m     16\u001b[39m \n\u001b[32m     17\u001b[39m \u001b[38;5;66;03m# Core interfaces - import directly from specific modules to avoid circular imports\u001b[39;00m\n\u001b[32m---> \u001b[39m\u001b[32m18\u001b[39m \u001b[38;5;28;01mfrom\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[34;01mcontinuallearning\u001b[39;00m\u001b[34;01m.\u001b[39;00m\u001b[34;01mevents\u001b[39;00m\u001b[34;01m.\u001b[39;00m\u001b[34;01minterfaces\u001b[39;00m\u001b[34;01m.\u001b[39;00m\u001b[34;01mstrategy_interfaces\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[38;5;28;01mimport\u001b[39;00m (\n\u001b[32m     19\u001b[39m     StrategyEventHandlerInterface \u001b[38;5;28;01mas\u001b[39;00m StrategyEventHandler,\n\u001b[32m     20\u001b[39m     LossComputationInterface,\n\u001b[32m     21\u001b[39m     BatchProcessorInterface,\n\u001b[32m     22\u001b[39m     MemoryManagerInterface,\n\u001b[32m     23\u001b[39m )\n\u001b[32m     24\u001b[39m \u001b[38;5;28;01mfrom\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[34;01mcontinuallearning\u001b[39;00m\u001b[34;01m.\u001b[39;00m\u001b[34;01mevents\u001b[39;00m\u001b[34;01m.\u001b[39;00m\u001b[34;01minterfaces\u001b[39;00m\u001b[34;01m.\u001b[39;00m\u001b[34;01mbase_interfaces\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[38;5;28;01mimport\u001b[39;00m (\n\u001b[32m     25\u001b[39m     EventDispatcherInterface \u001b[38;5;28;01mas\u001b[39;00m IEventDispatcher,\n\u001b[32m     26\u001b[39m )\n\u001b[32m     27\u001b[39m \u001b[38;5;28;01mfrom\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[34;01mcontinuallearning\u001b[39;00m\u001b[34;01m.\u001b[39;00m\u001b[34;01mevents\u001b[39;00m\u001b[34;01m.\u001b[39;00m\u001b[34;01minterfaces\u001b[39;00m\u001b[34;01m.\u001b[39;00m\u001b[34;01mutility_interfaces\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[38;5;28;01mimport\u001b[39;00m (\n\u001b[32m     28\u001b[39m     ComponentRegistryInterface \u001b[38;5;28;01mas\u001b[39;00m IComponentRegistry,\n\u001b[32m     29\u001b[39m )\n",
      "\u001b[36mFile \u001b[39m\u001b[32m/data1/jiashuo/codespace/lightning_continual_framework/continuallearning/events/interfaces/__init__.py:2\u001b[39m\n\u001b[32m      1\u001b[39m \u001b[38;5;66;03m# ========== Base Event System Interfaces ==========\u001b[39;00m\n\u001b[32m----> \u001b[39m\u001b[32m2\u001b[39m \u001b[38;5;28;01mfrom\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[34;01m.\u001b[39;00m\u001b[34;01mbase_interfaces\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[38;5;28;01mimport\u001b[39;00m (\n\u001b[32m      3\u001b[39m     \u001b[38;5;66;03m# Core event handling\u001b[39;00m\n\u001b[32m      4\u001b[39m     EventHandlerInterface,\n\u001b[32m      5\u001b[39m     AsyncEventHandlerInterface,\n\u001b[32m      6\u001b[39m     \u001b[38;5;66;03m# Event filtering and transformation\u001b[39;00m\n\u001b[32m      7\u001b[39m     EventFilterInterface,\n\u001b[32m      8\u001b[39m     EventTransformerInterface,\n\u001b[32m      9\u001b[39m     EventValidatorInterface,\n\u001b[32m     10\u001b[39m     \u001b[38;5;66;03m# Event dispatching\u001b[39;00m\n\u001b[32m     11\u001b[39m     EventDispatcherInterface,\n\u001b[32m     12\u001b[39m     AsyncEventDispatcherInterface,\n\u001b[32m     13\u001b[39m     BatchEventDispatcherInterface,\n\u001b[32m     14\u001b[39m )\n\u001b[32m     16\u001b[39m \u001b[38;5;66;03m# ========== Event Lifecycle Interfaces ==========\u001b[39;00m\n\u001b[32m     17\u001b[39m \u001b[38;5;28;01mfrom\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[34;01m.\u001b[39;00m\u001b[34;01mlifecycle_interfaces\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[38;5;28;01mimport\u001b[39;00m (\n\u001b[32m     18\u001b[39m     EventProcessorInterface,\n\u001b[32m     19\u001b[39m     EventMiddlewareInterface,\n\u001b[32m     20\u001b[39m     EventPipelineInterface,\n\u001b[32m     21\u001b[39m     EventChainInterface,\n\u001b[32m     22\u001b[39m )\n",
      "\u001b[36mFile \u001b[39m\u001b[32m/data1/jiashuo/codespace/lightning_continual_framework/continuallearning/events/interfaces/base_interfaces.py:22\u001b[39m\n\u001b[32m      8\u001b[39m \u001b[38;5;28;01mfrom\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[34;01mabc\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[38;5;28;01mimport\u001b[39;00m ABC, abstractmethod\n\u001b[32m      9\u001b[39m \u001b[38;5;28;01mfrom\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[34;01mtyping\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[38;5;28;01mimport\u001b[39;00m (\n\u001b[32m     10\u001b[39m     Any,\n\u001b[32m     11\u001b[39m     Dict,\n\u001b[32m   (...)\u001b[39m\u001b[32m     19\u001b[39m     Awaitable,\n\u001b[32m     20\u001b[39m )\n\u001b[32m---> \u001b[39m\u001b[32m22\u001b[39m \u001b[38;5;28;01mfrom\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[34;01mcontinuallearning\u001b[39;00m\u001b[34;01m.\u001b[39;00m\u001b[34;01mevents\u001b[39;00m\u001b[34;01m.\u001b[39;00m\u001b[34;01mcore\u001b[39;00m\u001b[34;01m.\u001b[39;00m\u001b[34;01mevent_types\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[38;5;28;01mimport\u001b[39;00m EventType, BaseEventData\n\u001b[32m     24\u001b[39m \u001b[38;5;66;03m# Type variables for generic event handling\u001b[39;00m\n\u001b[32m     25\u001b[39m E = TypeVar(\u001b[33m\"\u001b[39m\u001b[33mE\u001b[39m\u001b[33m\"\u001b[39m, bound=BaseEventData)\n",
      "\u001b[36mFile \u001b[39m\u001b[32m/data1/jiashuo/codespace/lightning_continual_framework/continuallearning/events/core/__init__.py:38\u001b[39m\n\u001b[32m     25\u001b[39m \u001b[38;5;28;01mfrom\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[34;01m.\u001b[39;00m\u001b[34;01mhandlers\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[38;5;28;01mimport\u001b[39;00m (\n\u001b[32m     26\u001b[39m     BaseEventHandler,\n\u001b[32m     27\u001b[39m     FunctionalEventHandler,\n\u001b[32m   (...)\u001b[39m\u001b[32m     34\u001b[39m     with_error_handling,\n\u001b[32m     35\u001b[39m )\n\u001b[32m     37\u001b[39m \u001b[38;5;66;03m# === Basic Event Dispatcher ===\u001b[39;00m\n\u001b[32m---> \u001b[39m\u001b[32m38\u001b[39m \u001b[38;5;28;01mfrom\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[34;01m.\u001b[39;00m\u001b[34;01mdispatcher\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[38;5;28;01mimport\u001b[39;00m (\n\u001b[32m     39\u001b[39m     DispatcherStats,\n\u001b[32m     40\u001b[39m     EventDispatcher,\n\u001b[32m     41\u001b[39m     AsyncEventDispatcher,\n\u001b[32m     42\u001b[39m     global_dispatcher,\n\u001b[32m     43\u001b[39m     global_async_dispatcher,\n\u001b[32m     44\u001b[39m     temporary_handler,\n\u001b[32m     45\u001b[39m )\n\u001b[32m     47\u001b[39m \u001b[38;5;66;03m# === Component Registry ===\u001b[39;00m\n\u001b[32m     48\u001b[39m \u001b[38;5;28;01mfrom\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[34;01m.\u001b[39;00m\u001b[34;01mcomponent_registry\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[38;5;28;01mimport\u001b[39;00m (\n\u001b[32m     49\u001b[39m     ComponentType,\n\u001b[32m     50\u001b[39m     ComponentStatus,\n\u001b[32m   (...)\u001b[39m\u001b[32m     55\u001b[39m     AdvancedComponentRegistry,\n\u001b[32m     56\u001b[39m )\n",
      "\u001b[36mFile \u001b[39m\u001b[32m/data1/jiashuo/codespace/lightning_continual_framework/continuallearning/events/core/dispatcher.py:34\u001b[39m\n\u001b[32m     31\u001b[39m \u001b[38;5;28;01mimport\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[34;01mtime\u001b[39;00m\n\u001b[32m     32\u001b[39m \u001b[38;5;28;01mimport\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[34;01mweakref\u001b[39;00m\n\u001b[32m---> \u001b[39m\u001b[32m34\u001b[39m \u001b[38;5;28;01mfrom\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[34;01m.\u001b[39;00m\u001b[34;01m.\u001b[39;00m\u001b[34;01minterfaces\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[38;5;28;01mimport\u001b[39;00m (\n\u001b[32m     35\u001b[39m     EventHandlerInterface,\n\u001b[32m     36\u001b[39m     AsyncEventHandlerInterface,\n\u001b[32m     37\u001b[39m     EventDispatcherInterface,\n\u001b[32m     38\u001b[39m     EventMiddlewareInterface,\n\u001b[32m     39\u001b[39m     EventObserverInterface,\n\u001b[32m     40\u001b[39m     EventValidatorInterface,\n\u001b[32m     41\u001b[39m )\n\u001b[32m     42\u001b[39m \u001b[38;5;28;01mfrom\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[34;01m.\u001b[39;00m\u001b[34;01m.\u001b[39;00m\u001b[34;01mcore\u001b[39;00m\u001b[34;01m.\u001b[39;00m\u001b[34;01mevent_types\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[38;5;28;01mimport\u001b[39;00m BaseEventData, EventType, EventFactory, E\n\u001b[32m     43\u001b[39m \u001b[38;5;28;01mfrom\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[34;01m.\u001b[39;00m\u001b[34;01m.\u001b[39;00m\u001b[34;01mcore\u001b[39;00m\u001b[34;01m.\u001b[39;00m\u001b[34;01mhandlers\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[38;5;28;01mimport\u001b[39;00m BaseEventHandler, AsyncEventHandler\n",
      "\u001b[31mImportError\u001b[39m: cannot import name 'EventHandlerInterface' from partially initialized module 'continuallearning.events.interfaces' (most likely due to a circular import) (/data1/jiashuo/codespace/lightning_continual_framework/continuallearning/events/interfaces/__init__.py)"
     ]
    }
   ],
   "source": [
    "# 导入必要组件\n",
    "from continuallearning.events import (\n",
    "    EventType,\n",
    "    EventFactory,\n",
    "    FunctionalEventHandler,\n",
    "    global_dispatcher,\n",
    ")\n",
    "\n",
    "\n",
    "# 🎪 步骤1: 创建事件处理器（就是一个函数！）\n",
    "def hello_handler(event):\n",
    "    print(f\"🎉 收到事件: {event.event_type.value}\")\n",
    "    print(f\"📄 事件数据: {event.data}\")\n",
    "    return None\n",
    "\n",
    "\n",
    "# 🔧 步骤2: 包装成事件处理器\n",
    "handler = FunctionalEventHandler(\n",
    "    event_types=[EventType.TASK_STARTED],\n",
    "    handler_func=hello_handler,\n",
    "    name=\"HelloWorldHandler\",\n",
    ")\n",
    "\n",
    "# 📝 步骤3: 注册处理器\n",
    "global_dispatcher.register_handler(handler)\n",
    "\n",
    "# 🚀 步骤4: 发布事件\n",
    "event = (\n",
    "    EventFactory.task(EventType.TASK_STARTED, task_id=1)\n",
    "    .data({\"message\": \"Hello Event World!\"})\n",
    "    .build()\n",
    ")\n",
    "\n",
    "# ✨ 步骤5: 分发事件并查看结果\n",
    "result = global_dispatcher.dispatch(event)\n",
    "print(f\"✅ 处理结果: {result.success}\")"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "lightning_continual_framework",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.13"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
